﻿@model PH.Model.Schools.StudentModel

<div class="GeneralEdit" id="fmStudent">
    <ul>
        <li>
            <label for="txtStudentNo">身份证号：</label>
            <input type="text" class="k-textbox" id="txtStudentNo" name="studentNo" value="@Model.StudentNo" maxlength="25" required validationMessage="请输入身份证号"/>
        </li>
        <li>
            <label for="txtStudentName">学生姓名：</label>
            <input type="text" class="k-textbox" id="txtStudentName" name="studentName" value="@Model.RealName" maxlength="50" pattern=".{2,}" required validationMessage="请输入学生姓名" />
            <span class="k-invalid-msg" data-for="studentName"></span>
        </li>
        <li>
            <label for="ddlSex">性别：</label>
            <select id="ddlSex">
                <option value="1" @(Model.Sex == 1 ? "selected='selected'" : "")>男</option>
                <option value="2" @(Model.Sex == 2 ? "selected='selected'" : "")>女</option>
            </select>
        </li>
        <li>
            <label for="ddlClass">所在班级：</label>
            <select id="ddlClass" name="class">
                @foreach (var cla in (PH.Model.Schools.ClassCollection)ViewBag.Classes)
                {
                    <option value="@cla.ID" @(Model.ClassID == cla.ID ? "selected='selected'" : "") >@cla.ClassName</option>
                }
            </select>
        </li>
        <li>
            <label for="txtMobile">联系手机：</label>
            <input type="tel" class="k-textbox" id="txtMobile" name="mobile" value="@Model.Mobile" maxlength="15" />
        </li>
        <li>
            <label for="txtMobile">原毕业学校：</label>
            <input type="text" id="txtOriSchoolCode" name="oriSchoolCode" data-value="@Model.OriSchoolCode" />
            <span style="display:block; color:red; font-size:12px; padding-left:25%">初一、高一、大一 学生必填</span>
        </li>
        <li class="editButtons">
            <button id="btnSaveStudent" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="init">
    $("#ddlClass").kendoDropDownList();
    $("#ddlSex").kendoDropDownList();

    var allSchools = Whale.Remote.GetEntity({
        url: "/School/SchoolInfo/GetSchools",
        parameters: {
            bureauID: 1
        }
    });
    $("#txtOriSchoolCode").kendoComboBox({
        placeholder: "请选择原毕业学校...",
        filter: "contains",
        dataTextField: "SchoolName",
        dataValueField: "Code",
        dataSource: allSchools,
        select: function (e) {
            var item = this.dataItem(e.item.index());
            $("#txtOriSchoolCode").attr("data-value", item.Code);
        },
        dataBound: function (e) {

        }
    });
</script>

<script class="save_student">
    $(function () {
        var validator = $("#fmStudent").kendoValidator().data("kendoValidator");
        $("#btnSaveStudent").click(function (e) {
            if (validator.validate()) {
                var values = {
                    stuID: "@Model.ID",
                    guid: "@Model.Guid",
                    schoolID: "@Model.SchoolID",
                    classID: $("#ddlClass").data("kendoDropDownList").value(),
                    realName: $("#txtStudentName").val(),
                    studentNo: $("#txtStudentNo").val(),
                    sex: $("#ddlSex").data("kendoDropDownList").value(),
                    mobile: $("#txtMobile").val(),
                    oriSchoolCode: $("#txtOriSchoolCode").attr("data-value")
                };

                Whale.Remote.Operation({
                    url: "/School/Student/SaveStudent",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_student").length > 0)
                            $("#grid_student").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>

